﻿using System;

namespace AnimalApp
{
    // 动物基类
    abstract class Animal
    {
        public abstract void Voice();
    }

    // 猫类
    class Cat : Animal
    {
        public override void Voice()
        {
            Console.WriteLine("喵喵喵~");
        }
    }

    // 猪类
    class Pig : Animal
    {
        public override void Voice()
        {
            Console.WriteLine("哼哼哼~");
        }
    }

    // 狗类
    class Dog : Animal
    {
        public override void Voice()
        {
            Console.WriteLine("汪汪汪~");
        }
    }

    // 宠物店类
    class Store
    {
        public static Animal GetInstance(string animalType)
        {
            switch (animalType.ToLower())
            {
                case "dog":
                    return new Dog();
                case "pig":
                    return new Pig();
                default:
                    return new Cat();
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            // 测试不同动物的叫声
            Console.WriteLine("请输入动物类型(dog/pig/cat)：");
            string input = Console.ReadLine();

            Animal animal = Store.GetInstance(input);
            Console.Write($"{animal.GetType().Name}的叫声：");
            animal.Voice();

            // 测试所有动物
            Console.WriteLine("\n所有动物测试：");
            Animal[] animals = { new Cat(), new Pig(), new Dog() };
            foreach (var a in animals)
            {
                Console.Write($"{a.GetType().Name}的叫声：");
                a.Voice();
            }
        }
    }
}